﻿using System;
using System.Collections.Generic;

namespace Tatibah
{
    /// <summary>
    /// This class represents a Style that will be applied to 1 or several Paragraphs
    /// </summary>
    public class Style: BaseParagraphFormatting
    {
        /// <summary>
        /// The Name of the Style
        /// </summary>
        public string Name;

        /// <summary>
        /// The name of this Styles parent
        /// </summary>
        public string BasedOn = "Normal";
        private string id;
        private static List<Style> allStyles = new List<Style>();

        /// <summary>
        /// Create a Style from a Name and Parent StyleName
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="BasedOn"></param>
        public Style(string Name, string BasedOn)
        {
            this.Name = Name;
            this.BasedOn = BasedOn;
            allStyles.Add(this);
        }

        /// <summary>
        /// Create a Style from a Name
        /// </summary>
        /// <param name="Name"></param>
        public Style(string Name)
        {
            this.Name = Name;
            allStyles.Add(this);
        }

        #region P R O P E R T I E S
        /// <summary>
        /// Get the Internal Id of the Style,only available after the Style has been saved to the document
        /// </summary>
        public string Id
        {
            get { return id; }
        }

        #endregion  P R O P E R T I E S

        /// <summary>
        /// Function for Internal use.
        /// </summary>
        /// <param name="Id"></param>
        public void ReservedI(string Id)
        {
            if (string.IsNullOrEmpty(id))
                id = Id;
            else
                throw new Exception("Style Id can only be set once.");
        }


        /// <summary>
        /// Get the Styles Id from the Style Name
        /// </summary>
        /// <param name="StyleName"></param>
        /// <returns></returns>
        public static string GetStyleId(string StyleName)
        {
            
            foreach (Style item in allStyles)
            {
                if (item.Name == StyleName) return item.id;
            }
            return "";
        }
    }
}
